import allure,time
from selenium.webdriver.common.by import By
from page.page_common_steps import PageCommonSteps
from base.base_common import BaseCommon


class PageTypesRole(PageCommonSteps):
    def __init__(self, driver):
        super().__init__(driver)  # 继承公用方法


        # 元素：系统管理
        self.system_management = By.XPATH, "//*[contains(text(),'系统管理')]"
        # 元素：角色类型管理
        self.roletype_management = By.XPATH, "//*[contains(text(),'角色类型管理')]"
        # 元素：新增
        self.type_added = By.XPATH, "//*[text()='新增']"
        # 元素：类型名称
        self.type_name = By.XPATH, "//*[text()='类型名称' ]/following-sibling::div/div[1]/input"
        # 元素：类型-确定
        self.type_confirm = By.XPATH, "//*[@class='ivu-btn ivu-btn-primary ivu-btn-large']"
        # 元素：保存成功
        self.save_successfully = By.XPATH, "//*[text()='保存成功']"
        # 元素：删除-确定
        self.delete_confirm = By.XPATH, "//*[@class='ivu-btn ivu-btn-text']/following-sibling::button"
        # 元素：定位"自动化角色类型"
        self.existing_name = By.XPATH, "//*[text()='自动化角色类型']"
        # 元素：角色管理
        self.role_management = By.XPATH, "//*[contains(text(),'角色类型管理')]/following-sibling::li[contains(text(),'角色管理')]"
        # 元素：角色名称
        self.character_name = By.XPATH, "//*[text()='新增角色']/..//following-sibling::div[1]/form/div[1]/div/div/input"
        # 元素：选择角色类型
        self.select_role_type = By.XPATH, "//*[text()='新增角色']/../following-sibling::div[1]/form/div[2]/div/div/div/div/input"
        # 元素：角色名称-确定
        self.role_determination = By.XPATH, "//*[text()='新增角色']/../following-sibling::div[2]/div/button/span[text()='确定']"
        # 元素：编辑角色-选角色类型
        self.edit_3 = By.XPATH, "//*[text()='编辑角色']/../following-sibling::div[1]/form/div[2]/div/div//div/div/input"

        # 元素：权限-取消或勾选
        self.permission_selection = By.XPATH, "//*[@class='left_box treeStyle']/div/ul[1]/li/label/span/input"
        # 元素：保存
        self.permission_save = By.XPATH, "//*[@class='ivu-btn ivu-btn-primary ivu-btn-circle' and @type='button']/span[text()='保存']"








    @allure.step(title="操作步骤:角色类型管理")
    def click_role_management(self):
        return self.click(self.role_management)  # 点击角色管理

    @allure.step(title="操作步骤:操作流程")
    def click_role_operate(self, operation_role):
        role_operation = By.XPATH, "//*[@class='ivu-table-tbody']/tr[1]/td[8]/div/div/span[text()='{0}']".format(operation_role)
        self.click(role_operation)   # 点击编辑、删除、禁用、编辑权限、复制角色


    @allure.step(title="操作步骤:下拉选择倒数第一个角色类型")
    def click_role_edit1(self):
        self.click(self.edit_3)   # 点击选角色类型
        BaseCommon.choose_1ist_select1(self)  # 选择下拉倒数第一个角色类型

    @allure.step(title="操作步骤:角色类型管理")
    def click_role_determination(self):
        return self.click(self.role_determination)  # 点击确定


    @allure.step(title="操作步骤:新增角色名称")
    def click_role_added(self, char_name):
        self.click(self.type_added)  # 点击新增
        self.input(self.character_name, char_name)  # 输入角色名称
        self.click(self.select_role_type)   # 点击选角色类型
        BaseCommon.choose_1st_select(self)  # 选择下拉第一个角色类型


    @allure.step(title="操作步骤:系统管理")
    def click_system_management(self):
        return self.click(self.system_management)  # 点击系统管理

    @allure.step(title="操作步骤:角色类型管理")
    def click_roletype_management(self):
        return self.click(self.roletype_management)  # 点击角色类型管理


    @allure.step(title="操作步骤:角色类型管理")
    def get_existing_name(self):
        return self.find_el(self.existing_name).text  # 点击角色类型管理

    @allure.step(title="操作步骤:新增流程")
    def click_type_added(self, name1):
        self.click(self.type_added)  # 点击新增
        self.input(self.type_name, name1)  # 输入角色类型名称
        self.click(self.type_confirm)  # 点击确定

    @allure.step(title="操作步骤:编辑流程")
    def click_type_operate(self, operation_type):
        operation_item = By.XPATH, "//*[@class='ivu-table-tbody']/tr[last()]/td[last()]/div/div/span[text()='{0}']".format(operation_type)
        self.click(operation_item)   # 点击编辑、删除、禁用

    @allure.step(title="操作步骤:编辑流程")
    def click_type_confirm(self):
        return self.click(self.type_confirm)  # 点击编辑-确定


    @allure.step(title="操作步骤:删除流程")
    def click_type_delete(self):
        return self.click(self.delete_confirm)  # 点击删除-确定

    @allure.step(title="操作步骤:获取保存成功")
    def get_save_successfully(self):
        return self.find_el(self.save_successfully).text  # 获取保存成功

    @allure.step(title="操作步骤:删除-确定")
    def click_save_successfully(self):
        return self.click(self.delete_confirm).text  # 删除-确定